<?php
declare(strict_types=1);

use app\middleware\Jwt;
use app\middleware\Sign;
use think\facade\Env;
use think\facade\Request;
use think\facade\Route;

// 获取sign表示
$header_info = Request::header();

// swagger
Route::get('/swagger', '\app\api\controller\Swagger@index');
// download
Route::get('/download', 'api/Index/download');
// 注册界面
Route::get('/reg/:invite_code', 'api/Index/reg');
// 支付宝app支付回调
Route::any('/0ad162451b1b1561081de08b815bad53/alipay-pay/notify', '\app\api\version\v1\Payment@alipayNotify');

if (isset($header_info['sign']) || (isset($header_info['token']) && Env::get('APP_DEBUG') && ($header_info['token'] == '123456'))) {

    Route::domain($header_info['host'], function () {
        // 上传图片
        Route::any('/upImg', '\app\api\version\v1\Index@upload');
        // 上传文件
        Route::any('/upFile', '\app\api\version\v1\Index@image');

        Route::group(function () {
            // 登陆记录
            Route::get(':version/getLoginLog', '\app\api\version\:version\QueryList@getLoginLog');
            // 删除登陆记录
            Route::get(':version/deleteLoginLog', '\app\api\version\:version\QueryList@deleteLoginLog');
            // 我的社区
            Route::get(':version/getTeamList', '\app\api\version\:version\QueryList@getTeamList');
            // 我的直推
            Route::get(':version/getInviteList', '\app\api\version\:version\QueryList@getInviteList');

            // 同步数据
            Route::post('syncData$', 'api/SyncClientData/index');

        })->middleware([Sign::class, Jwt::class]);

        Route::group(function () {
            // 检测手机
            Route::get('checkMobile$', 'api/Index/checkMobile');
            // 短信发送
            Route::post('shayuSms$', 'api/SendSms/shayuSms');
            // 短信验证
            Route::post('verifySms$', 'api/SendSms/verifySms');

            // 注册
            Route::post(':version/register$', '\app\api\version\:version\Login@register');
            // 登录
            Route::post(':version/authLogin$', '\app\api\version\:version\Login@index');
            // 重置密码
            Route::post(':version/setPassword$', '\app\api\version\:version\Login@setPassword');

        })->middleware(Sign::class);

        // 获取配置
        Route::get(':version/getConfigDetail', '\app\api\version\:version\Config@getConfigDetail');

        // 资讯列表
        Route::get(':version/articleList', '\app\api\version\:version\Article@list');
        Route::get(':version/questionList', '\app\api\version\:version\Article@questionList');
        // 资讯详情
        Route::get(':version/articleRead', '\app\api\version\:version\Article@read');

        // 生成Sign/验证Sign
        Route::resource(':version/sign', \app\api\version\v1\Sign::class);
        // 生成Token/验证Token
        Route::resource(':version/token', \app\api\version\v1\Token::class);

        Route::post('checkMobile$', 'api/Index/checkMobile');
    });
} else {
    // 异常
    Route::miss(function () {
        return '404 Not Found!';
    });
}
